def prime(d):
    s = True
    for m in range(2, int(d ** 0.5)+1):
        if d % m == 0:
            s = False
            break
    return s
h = int(input())
if h < 1000 or h > 9999:
    print(0)
else:
    nbvc = str(h)
    gj = 0
    for u in range(len(nbvc)):
        for y in range(u+1, len(nbvc)+1):
            num = int(nbvc[u:y])
            if prime(num):
                gj = max(gj, num)
    print(gj)